package com.uchiha.nova.mainService.wrapper;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.uchiha.nova.core.model.entity.RoleEntity;
import com.uchiha.nova.core.model.vo.RoleVO;
import com.uchiha.nova.core.tool.support.BaseEntityWrapper;
import com.uchiha.nova.core.tool.util.SpringUtil;
import com.uchiha.nova.mainService.service.IRoleService;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 角色信息  包装类,返回视图层所需的字段
 *
 * @author Uchihashiamu
 */
public class RoleWrapper extends BaseEntityWrapper<RoleEntity, RoleVO>  {
  
  IRoleService roleService = SpringUtil.getBean(IRoleService.class);
  
	public static RoleWrapper build() {
		return new RoleWrapper();
 	}

	@Override
	public RoleVO entityVO(RoleEntity roleEntity) {
		RoleVO roleVO = new RoleVO();
		BeanUtil.copyProperties(roleEntity, roleVO);

		return roleVO;
	}
	public List<RoleVO> listVO(List<RoleEntity> list) {
		List<RoleVO> collect = list.stream().map(item -> {
            RoleVO roleVO = new RoleVO();
		    BeanUtil.copyProperties(item, roleVO);			
			return roleVO;
		}).collect(Collectors.toList());
		return collect;
    // return ForestNodeMerger.merge(collect);
	}
  
  	@Override
	public IPage<RoleVO> pageVO(IPage<RoleEntity> pages) {
		IPage<RoleVO> page = pages.convert(item->{
            RoleVO roleVO = new RoleVO();
		    BeanUtil.copyProperties(item, roleVO);			
			return roleVO;
		});
		return page;
	}
}
